<?php
class TestController extends CController {
	public function actionIndex() {
		$list = array (
			
			array (
				
				'id' => 1, 
				'name' => '食品', 
				'parent' => 0 
			), 
			array (
				
				'id' => 2, 
				'name' => '水果', 
				'parent' => 1 
			), 
			array (
				
				'id' => 3, 
				'name' => '蔬菜', 
				'parent' => 1 
			), 
			array (
				
				'id' => 4, 
				'name' => '桃子', 
				'parent' => 2 
			), 
			array (
				
				'id' => 5, 
				'name' => '西瓜', 
				'parent' => 2 
			), 
			array (
				
				'id' => 6, 
				'name' => '香蕉', 
				'parent' => 2 
			), 
			array (
				
				'id' => 7, 
				'name' => '芹菜', 
				'parent' => 3 
			), 
			array (
				
				'id' => 8, 
				'name' => '白菜', 
				'parent' => 3 
			), 
			array (
				
				'id' => 9, 
				'name' => '青菜', 
				'parent' => 3 
			), 
			array (
				
				'id' => 10, 
				'name' => '萝卜', 
				'parent' => 3 
			), 
			array (
				
				'id' => 11, 
				'name' => '牛肉', 
				'parent' => 15 
			), 
			array (
				
				'id' => 12, 
				'name' => '羊肉', 
				'parent' => 15 
			), 
			array (
				
				'id' => 13, 
				'name' => '猪肉', 
				'parent' => 15 
			), 
			array (
				
				'id' => 15, 
				'name' => '肉类', 
				'parent' => 1 
			) 
		);
		$tree = new Tree ( 'root' );
		shuffle ( $list );
		foreach ( $list as $obj ) {
			$tnode = new Tree ( $obj ['name'], $obj ['id'], $obj ['parent'] );
			$pnode = $tree->getNodeById ( $obj ['parent'] );
			if ($pnode != false) {
				$pnode->addChild ( $tnode );
			} else {
				$tree->addChild ( $tnode );
			}
		}
		$body = $tree->view ();
		$tree->flush ();
		$body .= $tree->view ();
		print_r($body);
	}
	function actionTest1(){
		$smarty = Yii::app ()->smarty;
		$purview = new Purview();
		$left = $purview->getPurview();
		$smarty->assign("left",$left);
		$smarty->display ( 'index.html' );
	}
}
?>